<?php

class ml_biz_pinboardOutput {
    
    private $goods_data;
    private $aid;
    
    private $aRid = array();
    private $aUid = array();
    private $aNicks = array();
    private $aAttitude = array();
    private $aLikeCnt = array();
    private $aCmtCnt = array();
    private $aQuoteCnt = array();
    
    public function __construct($data, $aUid, $aRid, $aid){
        
        $this->goods_data = $data;
        $this->aRid = $aRid;
        $this->aUid = $aUid;
        $this->aid = $aid;
    }
    
    
    public function get_nick(){
        
        $this->aNicks = ml_tool_nick::uids2nicks($this->aUid);
        if (empty($this->aNicks)) {
            $oAccount = new ml_model_dbUserAccount();
            $rs = $oAccount->getNicksByUids($this->aUid);
            $this->aNicks = $oAccount->get_data();
        }
    }
    
    public function get_cnt()
    {
        $oRedis = new ml_model_rdsCount();
        $rs = $oRedis->getAttitudeCount($this->aRid);
        $this->aLikeCnt = $oRedis->get_data();
        $re=$oRedis->getCommentCount($this->aRid);
        $this->aCmtCnt=$oRedis->get_data();
        
        /**
         * @todo
        */
        
    }
    
    public function get_attitude()
    {
        if($this->aid)
        {
            $oIlike = new ml_model_dbILike();
            $rs = $oIlike->getListByUidRids($this->aid , $this->aRid);
            $this->aAttitude = Tool_array::format_2d_array($oIlike->get_data() , 'content_rid' , Tool_array::FORMAT_VALUE2VALUE2 ,'attitude');
        }
    }
    
    public function render_html_list()
    {
        if (empty($this->goods_data)) return ;
        
        
        $this->get_nick();
        $this->get_cnt();
        $this->get_attitude();
        
        foreach ($this->goods_data as $k => $row)
        {
            $this->goods_data[$k]['rid'] = $row['content_rid'];
            $this->goods_data[$k]['nick'] = $this->aNicks[$row['uid']];
            $this->goods_data[$k]['like_cnt'] = intval($this->aLikeCnt[$row['content_rid']]);
            $this->goods_data[$k]['cmt_cnt'] = intval($this->aCmtCnt[$row['content_rid']]);
            $this->goods_data[$k]['quote_cnt'] = intval($this->aQuoteCnt[$row['content_rid']]);
            $this->goods_data[$k]['is_attitude'] = isset($this->aAttitude[$row['content_rid']]) ? true : false;
            $this->goods_data[$k]['attitude_score'] = $this->aAttitude[$row['content_rid']];
            $this->goods_data[$k]['type_xrank'] = ML_CONTENT_XRANK_GOODS;
        }
        
        
        
        return ml_tool_pinOutput::parsePinboardTpl($this->goods_data , false);
    }
}